package com.maylann.ratiocheater.model;

import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * by Maylann
 */
public class Peer {

    private String id;

    public Peer() {
        this.id = genPeerId();
    }

    public String getId() {
        return id;
    }


    private String genPeerId() {
        int[] bs = genRandomBytes();
        StringBuilder sb = new StringBuilder(bs.length * 3);
        for (int b : bs) {
            int c = b & 0xFF;
            if (c < 16) {
                sb.append('0');
            }
            sb.append(Integer.toHexString(c));
        }

        return sb.toString();
    }

    public int[] genRandomBytes() {
        Random r = new Random();
        int[] b = new int[7];
        for(int i = 0; i < b.length; i++){
            b[i] = r.nextInt();
        }
        return b;
    }
}
